﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApiTest0001.Domain.Entity;

namespace WebApiTest0001.Domain
{
    public class DbInitializer
    {
        public static void Seed()
        {
            using var db = new Admin3200DbContext();
            db.Database.EnsureCreated();

            var hasUsers = db.Users.Any();

            if (!hasUsers)
            {
                var role = new Roles
                {
                    RoleName = "管理员",
                    Description = "这是一个管理员",
                };

                db.Roles.Add(role);

                db.SaveChanges();

                db.Users.AddRange(new Users[]
                {
                    new Users
                    {
                        Username="hhm",
                        Password="6668",
                        RolesId=role.Id
                    },
                    new Users
                    {
                        Username="zxy",
                        Password="99998",
                        RolesId=role.Id
                    }
                });

                db.SaveChanges();

            }
        }
    }
}
